﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemSensorLog : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog
    {
        #region Public Members

        #region Value

        private string _Value;
        partial void OnBeforeValuePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterValuePropertyChanged();
        public string Value
        { 
            get
            {
                return _Value;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Value = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Value);
                    OnBeforeValuePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Value", eventData.Value, true, true);
                        OnAfterValuePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ValueTimestamp

        private System.DateTime _ValueTimestamp;
        partial void OnBeforeValueTimestampPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterValueTimestampPropertyChanged();
        public System.DateTime ValueTimestamp
        { 
            get
            {
                return _ValueTimestamp;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ValueTimestamp = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _ValueTimestamp);
                    OnBeforeValueTimestampPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ValueTimestamp", eventData.Value, true, true);
                        OnAfterValueTimestampPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemSensorId

        private long _WorkItemSensorId;
        partial void OnBeforeWorkItemSensorIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkItemSensorIdPropertyChanged();
        public long WorkItemSensorId
        { 
            get
            {
                return _WorkItemSensorId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemSensorId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkItemSensorId);
                    OnBeforeWorkItemSensorIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemSensorId", eventData.Value, true, true);
                        OnAfterWorkItemSensorIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public WorkItemSensor WorkItemSensor { get; set; }
        #region LoadWorkItemSensorAsync

        public async System.Threading.Tasks.Task<WorkItemSensor> LoadWorkItemSensorAsync()
        {
            return await LoadWorkItemSensorAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemSensor> LoadWorkItemSensorAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkItemSensorField, global::Sidvall.WorkItemManager.Data.Relations.WorkItemSensorRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemSensorLogManager.LoadWorkItemSensorAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.WorkItemSensor;
        }
        public WorkItemSensor LoadWorkItemSensor(WorkItemSensor item)
        {
            LoadInstanceField("WorkItemSensor", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public WorkItemSensorLog Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Copy(this);
        }
        public WorkItemSensorLog Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog item)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Initialize(this, settings);
        }

        #endregion

        #region IWorkItemSensorLog Members

        string global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }
        System.DateTime global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.ValueTimestamp
        {
            get
            {
                return this._ValueTimestamp;
            }
            set
            {
                this._ValueTimestamp = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.WorkItemSensorId
        {
            get
            {
                return this._WorkItemSensorId;
            }
            set
            {
                this._WorkItemSensorId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkItemSensor global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.WorkItemSensor
        {
            get
            {
                return this.WorkItemSensor;
            }
            set
            {
                this.WorkItemSensor = (WorkItemSensor)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemSensorLog()
        {
        }
        public WorkItemSensorLog(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public WorkItemSensorLog(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Initialize(this);
        }

        #endregion
    }
}